In many video encoding methods, the amount of generated code varies depending on the character of an input image. Therefore, an encoding bit rate control technique is required for controlling the amount of generated code and keeping a constant encoding bit rate.
The amount of generated code closely relates to the quantization step size, and the amount of generated code is controlled by varying the quantization step size.
In test model 5 (abbreviated as “TM5”) of MPEG-2, code amount control is performed using a relationship between the quantization step size and the amount of generated code (see, for example, Non-Patent Document 1).
Below, the code amount control in TM5 of MPEG-2 will be explained.
In TM5 of MPEG-2, code amount control is performed using a unit called GOP (group of pictures), which may include I, P, and B pictures having different picture types such as I, P, and B picture types.
FIG. 6 shows a flowchart of the code amount control in TM5 of MPEG-2.
As shown in the flowchart, in the code amount control of TM5 in MPEG-2, in the first step S401, a complex index Xx for each picture type (x=i, p, b (which respectively correspond to I, P, and B pictures)) is computed by the following formula:Xx=Sx·<Qx>
In the above formula, x indicates the picture type, Sx indicates the amount of code generated for an image which has the same picture type as the present image and was encoded most recently, and <Qx> indicates an average of the quantization step size in the relevant encoding.
Generally, the code amount Sx is in inverse proportion to the quantization step size Qx. Therefore, computation of the complex index Xx gives a relationship between the amount of generated code and the quantization step size.
In the next step S402, a target amount Tx of code (x=i, p, b) for each picture type is computed by the following formulas.
                    [                  Formula          ⁢                                          ⁢          1                ]                                                                                  T            i                    =                      R                          1              +                                                                    N                    p                                    ⁢                                      X                    p                                                                                        X                    i                                    ⁢                                      K                    p                                                              +                                                                    N                    b                                    ⁢                                      X                    b                                                                                        X                    i                                    ⁢                                      K                    b                                                                                      ⁢                                  ⁢                              T            p                    =                      R                                          N                p                            +                                                                    N                    b                                    ⁢                                      K                    p                                    ⁢                                      X                    b                                                                                        X                    p                                    ⁢                                      K                    p                                                                                      ⁢                                  ⁢                              T            b                    =                      R                                          N                b                            +                                                                    N                    p                                    ⁢                                      K                    b                                    ⁢                                      X                    p                                                                                        X                    b                                    ⁢                                      K                    p                                                                                                          Formula        ⁢                                  ⁢                  (          1          )                    
Here, R indicates the amount of code allocated to the relevant GOP, Np indicates the number of P pictures in the GOP, Nb indicates the number of B pictures in the GOP, and Kp and Kb are constants.
The above formulas show that in order to set the target code amount Ti, P pictures are converted to I pictures in accordance with Xp/Xi, B pictures are converted to I pictures in accordance with Xb/Xi, and the target code amount Ti is computed based on the converted values, the numbers Np and Nb of pictures, and the amount R of code allocated to the GOP.
In order to set the target code amount Tp, B pictures are converted to P pictures in accordance with Xb/Xp, and the target code amount Tp is computed based on the converted value, the numbers Np and Nb of pictures, and the amount R of code allocated to the GOP.
In order to set the target code amount Tb, P pictures are converted to B pictures in accordance with Xp/Xb, and the target code amount Tb is computed based on the converted value, the numbers Np and Nb of pictures, and the amount R of code allocated to the GOP.
In the next step S403, based on the target code amount Tx set above for the pictures, the quantization step size for a small block as an encoding target is determined.
The quantization step size is computed based on an amount dx(j) of occupation of a virtual buffer and a reaction parameter r, by using the following formula.
                    [                  Formula          ⁢                                          ⁢          2                ]                                                                                  Q            x                    ⁡                      (            j            )                          =                                                            d                x                            ⁡                              (                j                )                                      ·            31                    r                                    Formula        ⁢                                  ⁢                  (          2          )                    
A virtual buffer used only for computing the quantization step size is set for each picture type, and the amount dx(j) of occupation thereof is updated by the following formula.
                    [                  Formula          ⁢                                          ⁢          3                ]                                                                                  d            x                    ⁡                      (            j            )                          =                                            d              x                        ⁡                          (              0              )                                +                                    G              x                        ⁡                          (                              j                -                1                            )                                -                                                    T                x                            ·                              (                                  j                  -                  1                                )                                                    MB              cnt                                                          Formula        ⁢                                  ⁢                  (          3          )                    
In the above formula, Gx(j) indicates the total amount of code generated until the j-th small block in the encoding target picture is encoded, and MBcnt indicates the number of small blocks in the relevant picture. The reaction parameter is computed by following formula.
                    [                  Formula          ⁢                                          ⁢          4                ]                                                            r        =                              2            ⋆            Bitrate                    Picture_rate                                    Formula        ⁢                                  ⁢                  (          4          )                    
In step S403 using the above-described method, the quantization step size Qx(j) assigned to a small block as the encoding target is determined based on the amount dx(j) of occupation of the virtual buffer and the reaction parameter r.
In the next step S404, each small block is subjected to quantization and encoding by using the determined quantization step size Qx(j).
In the next step S405, after encoding of one picture is completed, average <Qx> of the quantization step size is computed.
In the next step S406, (after encoding of one picture is completed,) the actual amount Sx of generated code is measured.
Based on the measured amount Sx of generated code and the computed average quantization step size <Qx>, in step S401 again, the complex index Xx for each picture type is updated.
In accordance with the above method, in TM5 of MPEG-2, a target amount of code is assigned to each picture when encoding the picture, thereby controlling the amount of generated code.
The above control method provides a stable operation if characteristics of the relevant video do not considerably change, and there is no overflow or underflow of a decoder buffer.
However, actual control must consider a scene change or the state of the decoder buffer.
For example, if a very simple scene continues in a static image such as telop, the quantization step size decreases very much. If an image (of a landscape, etc.) having a fine texture then appears, the image having a fine texture is encoded using a very small quantization step size, which causes an explosive increase in the amount of generated code and thus failure in the bit-rate control.
Accordingly, in a known proposed method, after detecting a scene change, the quantization step size is changed to a predetermined value (see, for example, Patent Document 1).
In this method, when a scene change has been detected, an initial value (of the quantization step size) defined for scene change is compared with a quantization step size computed through a rate control, and the larger quantization step size is used for the quantization.
In accordance with the above method, when a scene change has been detected, the quantization step size can be controlled, thereby preventing an explosive increase in the amount of generated code.    Non-Patent Document 1: MPEG-2, Test Model5(TM5), Doc.ISO/IECJTC1/SC29/WG11I/NO400, Test Model Editing Committee, pp. 59-63, Apr., 1993.    Patent Document 1: Japanese Unexamined Patent Application, First Publication No. H06-113271.